<?php

namespace App\Http\Controllers\Api;

use App\Mail\Authorized;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use SwooleTW\Http\Websocket\Facades\Websocket;

class TestController extends Controller
{
    protected $fd;

    public function index(Request $request)
    {
        $res = Websocket::broadcast()->emit('message', $this->translateContent('121', 'Msg'));

        dd($this->translateContent('121', 'Msg'));

        //邮箱测试
//        $email = $request->get('email');
//
//        $mail = Mail::to($email);
//
//        $code = 1234;
//
//        dd($mail->send(new Authorized($code)));
    }

    protected function translateContent($content, $type)
    {
        $result = [];

        if ($type == 'Msg') {
            $result['type'] = 'Msg';
            $result['content'] = $content;
        }

        if ($type == 'ImgMsg') {
            $result['type'] = 'ImgMsg';
            $result['content'] = image_url($content);
        }

        $result['user_id'] = $this->user->id;
        $result['user_nick_name'] = $this->user->nick_name;
        $result['user_avatar'] = image_url($this->user->avatar);
        $result['created_at'] = now()->toDateTimeString();

        return $result;
    }
}
